package com.inspur.edp.team.converter;

import com.inspur.edp.common.AbstractConverter;
import com.inspur.edp.common.CommonConstants;
import com.inspur.edp.team.domain.PaasTeam;
import com.inspur.edp.team.dto.Team;
import io.iec.edp.caf.sysmanager.api.data.user.User;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * 团队类转换器
 */
public class TeamConverter extends AbstractConverter {
    /**
     * 构造新增团队对象
     *
     * @param team
     * @param user
     * @return
     */
    public PaasTeam genPaasTeam(Team team, User user) {
        Timestamp time = Timestamp.valueOf(LocalDateTime.now());
        PaasTeam paasTeam = super.toTarget(team, PaasTeam.class);
        paasTeam.setId(UUID.randomUUID().toString())
                .setCreator(user.getName())
                .setCreatedTime(time)
                .setLastModifier(user.getName())
                .setLastModifiedTime(time)
                .setYn(CommonConstants.YN_YES);
        return paasTeam;
    }

    public Team convert2Team(PaasTeam paasTeam) {
        Team team = super.toTarget(paasTeam, Team.class);
        team.setCreatedTime(DateFormatUtils.format(paasTeam.getCreatedTime(), CommonConstants.DATE_FORMAT_PATTERN));
        team.setLastModifiedTime(DateFormatUtils.format(paasTeam.getLastModifiedTime(), CommonConstants.DATE_FORMAT_PATTERN));
        return team;
    }
}
